import window from '@ohos.window'
import common from '@ohos.app.ability.common';
class SubWindow{
  windowStage:window.WindowStage = null
   sub_windowClass:window.Window = null;
  context:common.UIAbilityContext
  createWindow(){
    let config = {name: "floatWindow", windowType: window.WindowType.TYPE_FLOAT, ctx: this.context};
    window.createWindow(config,(err, data)=>{
      if (err.code) {
        console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
        return;
      }
      this.sub_windowClass = data;
      this.sub_windowClass.moveWindowTo(300,300)
      this.sub_windowClass.resize(500,500)
      this.sub_windowClass.setUIContent('pages/SubPagePage')
      this.sub_windowClass.showWindow()
    })
  }
  showSubWindow(){

    this.windowStage.createSubWindow('mySubWindow',(err, data)=>{
      if (err.code) {
        console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
        return;
      }
      this.sub_windowClass = data;
      this.sub_windowClass.moveWindowTo(300,300)
      this.sub_windowClass.resize(500,500)
      this.sub_windowClass.setUIContent('pages/SubPagePage')
      this.sub_windowClass.showWindow()
    })
  }
  destroyWindow(){
    this.sub_windowClass.destroyWindow()
  }
}
export  default  new SubWindow()